home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / ctlib100.zip / INSTALL.LZH / QUEUES1.PAS < prev    next >
Pascal/Delphi Source File  |  1996-10-12  |  2KB  |  75 lines

  1. {**************************************************************************}
  2. {*  BitSoft Development, L.L.C.                                           *}
  3. {*  Copyright (C) 1995, 1996 BitSoft Development, L.L.C.                  *}
  4. {*  All rights reserved.                                                  *}
  5. {*  Containers Library demo                                               *}
  6. {**************************************************************************}
  7.  
  8. program Queues1;
  9.  
  10. {$X+}
  11.  
  12. { Sample program for using a queue }
  13.  
  14. uses Objects, Containr, ctLists, ctQueues,
  15.      {$ifdef Windows}
  16.      WinCtr;
  17.      {$else}
  18.      Crt;
  19.      {$endif}
  20.  
  21. type
  22.   PRequest = ^TRequest;
  23.   TRequest = object (TListNode)
  24.       ID : Integer;
  25.       Instruction : Integer;
  26.     constructor Init(AId, AInstruction : Integer);
  27.   end; { TRequest }
  28.  
  29. constructor TRequest.Init(AId, AInstruction : Integer);
  30. begin
  31.   TListNode.Init;
  32.   ID := AId;
  33.   Instruction := AInstruction;
  34. end;
  35.  
  36. var
  37.   InstructionQueue : PQueue;
  38.   Item : Pointer;
  39.  
  40. begin
  41.   ClrScr;
  42.  
  43.   { Create the queue }
  44.   InstructionQueue := New(PQueue, Init);
  45.  
  46.   { Insert items into the queue }
  47.   with InstructionQueue^ do
  48.   begin
  49.     Writeln('Enqueueing:  ID = 0, Instruction = 234');
  50.     Enqueue(New(PRequest, Init(0, 234)));
  51.     Writeln('Enqueueing:  ID = 1, Instruction = 735');
  52.     Enqueue(New(PRequest, Init(1, 735)));
  53.     Writeln('Enqueueing:  ID = 2, Instruction = 956');
  54.     Enqueue(New(PRequest, Init(2, 956)));
  55.     Writeln('Enqueueing:  ID = 3, Instruction = 164');
  56.     Enqueue(New(PRequest, Init(3, 164)));
  57.     Writeln('Enqueueing:  ID = 4, Instruction = 691');
  58.     Enqueue(New(PRequest, Init(4, 691)));
  59.   end; { with }
  60.   Writeln;
  61.  
  62.   { Extract items from the queue }
  63.   with InstructionQueue^ do
  64.   begin
  65.     repeat
  66.       Item := Remove;
  67.       with PRequest(Item)^ do
  68.         Writeln('Extracting:  ID = ', ID, ', Instruction number = ', Instruction:4);
  69.       FreeItem(Item);
  70.     until Count = 0;
  71.   end; { with }
  72.  
  73.   { Dispose of the queue }
  74.   Dispose(InstructionQueue, Done);
  75. end.